// 获取参数
var fs = require("fs");

module.exports = {
    // i 从1开始
    emptyDir(path){
        function deleteall(path) {
            var files = [];
            if(fs.existsSync(path)) {
                files = fs.readdirSync(path);
                files.forEach(function(file, index) {
                    var curPath = path + "/" + file;
                    if(fs.statSync(curPath).isDirectory()) { // recurse
                        deleteall(curPath);
                    } else { // delete file
                        fs.unlinkSync(curPath);
                    }
                });
                fs.rmdirSync(path);
            }
        };
        deleteall(path);
    },
    copyFile(path1,path2,callback) {
        // 拷贝文档
        let copyYuanMd = path1;
        let copyOverMd = path2;
        // 创建读取流
        let readableMd  = fs.createReadStream( copyYuanMd );
        // 创建写入流
        let writableMd  = fs.createWriteStream( copyOverMd );
        // 通过管道来传输流
        readableMd.pipe( writableMd );

        writableMd.on('close',function(){
            callback();
        });
    }
};